// var base_url = "http://shopsuite.dev.congred.com:65080"
// var base_url = "https://test.shopsuite.cn"
// var base_url = 'https://mjmh.meijiameihuo.com'
/* eslint-disable */
export function imgPath (src) {
  let pathFix = process.env.NODE_ENV === 'production' ? '/h5' : ''
  return window.location.origin + pathFix + src
}

export function jsonParse (res, key) {
  var data = JSON.parse(res)
  return data[key]
}

export function dataSub (date) {
  if (date) {
    var time = date.split(' ')
    return time[0]
  } else {
    return date
  }
}
export function formatDate (time) {
  if (!time) {
    time = new Date()
  }
  let year = time.getFullYear()
  let month = time.getMonth() + 1
  let monthT = month > 9 ? month : '0' + month
  return year + '-' + monthT
}
export function isClient () {
  let sUserAgent = navigator.userAgent.toLowerCase() // 输出：sUserAgent mozilla/5.0 (iphone cpu iphone os 9_1 like mac os x) applewebkit/601.1.46 (khtml, like gecko) version/9.0 mobile/13b143 safari/601.1
  let isyggiOSApp = sUserAgent.match(/yggiosapp/i) || false
  let isyggAndroidApp = sUserAgent.match(/android-ygg/i) || false
  if (isyggiOSApp || isyggAndroidApp) {
    return true
  } else {
    return false
  }
}
export function isSys () {
  let u = navigator.userAgent.toLowerCase() // 输出：sUserAgent mozilla/5.0 (iphone cpu iphone os 9_1 like mac os x) applewebkit/601.1.46 (khtml, like gecko) version/9.0 mobile/13b143 safari/601.1
  let isAndroid = u.indexOf('android') > -1 || u.indexOf('adr') > -1 // android终端
  let isiOS = u.indexOf('iphone') > -1 // ios终端
  let isWx = u.indexOf('micromessenger') > -1
  if (isiOS) {
    return 'ios'
  } else if (isWx) {
    return 'wx'
  } else if (isAndroid) {
    return 'android'
  } else {
    return null
  }
}
export function toNum (a) {
 var a = a.toString()
 var c = a.split('.')
 var num_place = ["","0","00","000","0000"],r=num_place.reverse()
 for (var i=0; i<c.length; i++){
  var len = c[i].length
  c[i] = r[len] + c[i]
 }
 var res= c.join('')
 return res
}
export function checkPlugin (a, b) {
  var a = toNum(a)
  var b = toNum(b)
  if (a == b) {
    return true
    // console.log("版本号相同！版本号为:"+a)
  } else if (a > b) {
    return true
    // console.log("版本号"+a+"是新版本!")
  } else {
    return false
    // console.log("版本号"+b+"是新版本!")
  }
}
export function urlencode (data) {
  var _result = []
  for (var key in data) {
    var value = data[key]
    if (value.constructor === Array) {
      value.forEach(function (_value) {
        _result.push(key + '=' + _value)
      })
    } else {
      _result.push(key + '=' + value)
    }
  }
  return _result.join('&')
}
export function mobile (tel) {
  let rules = /^[1][3,4,5,6,7,8,9][0-9]{9}$/
  return rules.test(tel)
}
export function uuid () {
  var s = []
  var hexDigits = '0123456789abcdef'
  for (var i = 0; i < 36; i++) {
    s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1)
  }
  s[14] = '4' // bits 12-15 of the time_hi_and_version field to 0010
  s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1) // bits 6-7 of the clock_seq_hi_and_reserved to 01
  s[8] = s[13] = s[18] = s[23] = '-'
  var uuid = s.join('')
  return uuid
}
export default {
  imgPath,
  jsonParse,
  dataSub,
  formatDate,
  isClient,
  urlencode,
  mobile,
  uuid,
  isSys,
  checkPlugin
}
